//
//  WZPNavigationController.m
//  WZPItem
//
//  Created by 王王喆平 on 16/7/5.
//  Copyright © 2016年 UI. All rights reserved.
//

#import "WZPNavigationController.h"

@implementation WZPNavigationController
-(void)viewDidLoad{
    [super viewDidLoad];

}
// 统一设置当前类下标题属性
+(void)load{

    // 调整导航条字体大小
    // 使用数组保存字体大小kk
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    // 获取当前类下的导航条外观
    UINavigationBar * bar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    [bar setTitleTextAttributes:dict];
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}
// 设置返回按钮位置
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    // 判断是否为根控制器 不是的话设置按钮
   //self.childViewControllers.count > 0  表示不是根控制器
    // 判断下是否是非根控制器
    if (self.childViewControllers.count) {
            // 设置返回按钮各种属性
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"返回" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [btn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
                [btn sizeToFit];
        // 修改按钮位置(修改内边距)
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        UIView *containView = [[UIView alloc] initWithFrame:btn.bounds];
        [containView addSubview:btn];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:containView];
        viewController.navigationItem.leftBarButtonItem = item;
        viewController.hidesBottomBarWhenPushed = YES;
        }
       [super pushViewController:viewController animated:animated];

}
-(void)back{

    [self popViewControllerAnimated:YES];

}
@end
